﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;



namespace bezeq_online_work
{
    public partial class loginscreen : Form
    {
        CONTROL.BusinessLogic controler;

        public loginscreen()
        {
            InitializeComponent();
            controler = new CONTROL.BusinessLogic();
        }
      
        private void button1_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                int t = controler.authentication(username.Text, password.Text);

                if (t > 0)
                {
                    view.mainmenu_ m = new view.mainmenu_(controler );
                    m.Show();
                    this.Hide();
                }
                else
                {
                    if (t == 0)
                    { MessageBox.Show("Wrong user name or password please try again"); }
                    else
                    { MessageBox.Show("too many wrong login attempts try again in 5 Minutes"); }

                }
            }
            catch (Exception ex)
            {
                // throw error message
                MessageBox.Show("an error has occurred. contact your administrator for further assistance /n /n" + ex.Message);
            }
            finally
            { username.Text = "";
            password.Text = "";

            }
        }

        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                this.button2.PerformClick();
            }
        }
        private void username_TextChanged(object sender, EventArgs e)
        {
           
        }

        private void username_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                this.button2.PerformClick();
            }
        }

        private void password_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                this.button2.PerformClick();
            }
        }
    }
}
